home *** CD-ROM | disk | FTP | other *** search
- Path: news.netins.net!trg1
- From: hhowe@trgnet.com (Harold Howe)
- Newsgroups: comp.lang.c++
- Subject: Encapsulation question.
- Date: Tue, 05 Mar 96 00:59:35 GMT
- Organization: Technology Resource Group
- Message-ID: <4hg701$goi@insosf1.netins.net>
- NNTP-Posting-Host: desm-22-14.dialup.netins.net
- X-Newsreader: News Xpress Version 1.0 Beta #3
-
- Greetings.
-
- Does the following violate encapsulation? Should an object tell a private
- member the address of other private members? I am using this on a grander
- scale, in which the Application class tells a private dialog object the
- address of a private configuration structure? The dialog class needs access
- to the structure so it can modify it, and this is how I tell the dialog where
- to look. Aside from using globals, does anyone have any better suggestions?
-
- class Application
- {
- private:
- int j;
- Dialog *dlg;
- public:
- Application(void) { dlg = new Dialog(&j); }
- }
-
- class Dialog
- {
- private:
- int *ptr;
- ... // plus other members which access ptr
- public:
- Dialog(int *addr) { ptr = addr } ;
- }
-
- int main()
- {
- Application app;
- }
-
-
- Thanks
- Harold Howe
- hhowe@trgnet.com
-